package com.ruiben.mall.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.ArrayList;
import java.util.List;

@ApiModel(value = "商品分类对象")
@Table(name = "product_category")
public class ProductCategory implements  Comparable<ProductCategory>{
    @Id
    @ApiModelProperty(hidden = true)
    private String id;

    /**
     * 类型名称
     */
    @ApiModelProperty(value = "分类名称",name = "typename",example = "家电",required = true)
    private String typename;

    /**
     * 上级id
     */
    @Column(name = "parent_id")
    private String parentId;

    /**
     * 是否禁用（1：未禁用；0：禁用）
     */
    @ApiModelProperty(value = "分类状态",name = "state",example = "0",required = false)
    private Short state;

    @Column(name = "imagePath")
    private String imagePath;

    /**
     * 排序
     */
    @ApiModelProperty(value = "分类排序",name = "sort",example = "50",required = false)
    private Integer sort;
    private List<ProductCategory> children = new ArrayList<ProductCategory>();


    public void setChildren(List<ProductCategory> children) {
        this.children = children;
    }

    public List<ProductCategory> getChildren() {
        return children;
    }

    public Short getState() {
        return state;
    }

    public void setState(Short state) {
        this.state = state;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    /**
     * @return id
     */
    public String getId() {
        return id;
    }

    /**
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * 获取类型名称
     *
     * @return name - 类型名称
     */
    public String getTypename() {
        return typename;
    }

    /**
     * 设置类型名称
     *
     * @param name 类型名称
     */
    public void setTypename(String name) {
        this.typename = name;
    }

    /**
     * 获取上级id
     *
     * @return parent_id - 上级id
     */
    public String getParentId() {
        return parentId;
    }

    /**
     * 设置上级id
     *
     * @param parentId 上级id
     */
    public void setParentId(String parentId) {
        this.parentId = parentId;
    }


    public String getImagePath() {
        return imagePath;
    }

    public void setImagePath(String imagePath) {
        this.imagePath = imagePath;
    }

    @Override
    public int compareTo(ProductCategory o) {
        if(this ==o){
            return 0;
        }
        else if (o!=null && o instanceof ProductCategory) {
            ProductCategory u = (ProductCategory) o;
            if(sort<=u.getSort()){
                return -1;
            }else{
                return 1;
            }
        }else{
            return -1;
        }
    }


}